package net.game;

import net.util.MathUtil;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Rectangle;


public abstract class AbstractGUIComponent implements GUIComponent
{
	protected Rectangle bounds;
	
	protected boolean mousein;
	
	protected float alpha = 0.6f;
	
	public final void renderBasic()
	{
		GL11.glLineWidth(3);
		GL11.glColor4f(0.5f, 0.5f, 0.5f, alpha);
		
		GL11.glBegin(GL11.GL_QUADS);
		GL11.glVertex2f(bounds.getX(), bounds.getY());
		GL11.glVertex2f(bounds.getX() + bounds.getWidth(), bounds.getY());
		GL11.glVertex2f(bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight());
		GL11.glVertex2f(bounds.getX(), bounds.getY() + bounds.getHeight());
		GL11.glEnd();
		GL11.glColor3f(0,0,0);
		GL11.glBegin(GL11.GL_LINE_STRIP);
		GL11.glVertex2f(bounds.getX(), bounds.getY());
		GL11.glVertex2f(bounds.getX() + bounds.getWidth(), bounds.getY());
		GL11.glVertex2f(bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight());
		GL11.glVertex2f(bounds.getX(), bounds.getY() + bounds.getHeight());
		GL11.glVertex2f(bounds.getX(), bounds.getY());
		GL11.glEnd();
	}
	
	public void render()
	{
		mousein = Mouse.isInsideWindow() && MathUtil.inRegion(Mouse.getX(), Mouse.getY(), bounds, true);
		
		if (mousein && alpha < 0.9)
		{
			alpha += 0.05f;
		}
		else if (!mousein && alpha > 0.6)
		{
			alpha -= 0.05f;
		}
		
		renderBasic();
	}
	
	public Rectangle getBounds()
	{
		return bounds;
	}

}
